package com.zx.map.dao.impl;

import com.zx.map.dao.SettleCardInfoDao;
import com.zx.map.dao.mapper.SettleCardInfoMapper;
import com.zx.map.dao.model.SettleCardInfo;
import com.zx.map.dao.model.SettleCardInfoExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 14-3-1
 * Time: 上午10:54
 * To change this template use File | Settings | File Templates.
 */
@Component("SettleCardInfoDao")
public class SettleCardInfoImpl implements SettleCardInfoDao {

    @Autowired
    private SettleCardInfoMapper mapper;

    /**
     * 新增
     */
    public Integer add(SettleCardInfo settleCardInfo) throws DataAccessException {
    	settleCardInfo.setCreateDate(new Date());
        int column = mapper.insert(settleCardInfo);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return settleCardInfo.getSettleId();
    }

    /**
     * 修改
     * @param settleCardInfo
     * @return
     * @throws DataAccessException
     */
    public Integer update(SettleCardInfo settleCardInfo) throws DataAccessException {
    	settleCardInfo.setUpdateDate(new Date());
        int column = mapper.updateByPrimaryKeySelective(settleCardInfo);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return settleCardInfo.getSettleId();
    }

    /**
     * 删除
     */
    public void delete(SettleCardInfo settleCardInfo) throws DataAccessException {
        int column = mapper.deleteByPrimaryKey(settleCardInfo.getSettleId());
        if (column != 1) {
            throw new RuntimeException("");
        }
    }

    /**
     * 分页查找
     */
	public List<SettleCardInfo> getPageByExample(int pageSize, int pageBegin,
			SettleCardInfoExample example) throws DataAccessException {
		return mapper.getPageByModel(pageSize, pageBegin, example); 
	}
	/**
	 * 查找条数
	 * 
	 * @param example
	 * @return
	 * @throws DataAccessException
	 */
	public int countByExample(SettleCardInfoExample example) throws DataAccessException {
		return mapper.countByExample(example);
	}

	/**
	 * 
	 */
	public List<SettleCardInfo> getListByExample(SettleCardInfoExample example)
			throws DataAccessException {
		return mapper.selectByExample(example); 
	}

	public SettleCardInfo selectByPrimaryKey(Integer key) throws DataAccessException {
		return mapper.selectByPrimaryKey(key);
	}
}
